/*
 * CadastrodeEstacao.java
 *
 * Created on 26 de Novembro de 2008, 16:22
 */

package br.faimg.pomar.visual;

import br.faimg.pomar.controle.BusinessDelegate.OrdemProducaoBusinesDelegate;
import br.faimg.pomar.controle.componentevisual.ComboProduto;
import br.faimg.pomar.controle.componentevisual.ItemProduto;
import br.faimg.pomar.controle.componentevisual.ItemTipo;
import javax.swing.JComboBox;

/**
 *
 * @author  diogo
 */
public class CadastrodeOrdemdeProducaoInclusao extends javax.swing.JDialog {

    /** Creates new form CadastrodeEstacao */
    public CadastrodeOrdemdeProducaoInclusao() {
        initComponents();  

        
        //Inlui os itens no combobox do tipo de estacao
        okButton.setText("Incluir");
        
        numeroTextField.setEnabled(true);
        ComboProduto itens = new ComboProduto();
        JComboBox temp = new JComboBox(itens.getList());
        tipoCombo.setModel(temp.getModel());
        
        
        //updateTable();
    }
    
    private void incluirItensCombo() {
        //Inlui os itens no combobox do tipo de estacao
        ComboProduto itens = new ComboProduto();
        JComboBox temp = new JComboBox(itens.getList());
        tipoCombo.setModel(temp.getModel());
        numeroTextField.setEnabled(true);
        qtdProdTextField.setEnabled(true);
        

    }
    

 /*   public CadastrodeOrdemdeProducaoInclusao(String codigo, String descricao, String tipo){
        
        initComponents();
        incluirItensCombo();
        cancelarButton.setText("Limpar");
        okButton.setText("Alterar");
        numeroTextField.setText(codigo);
        qtdProdTextField.setEnabled(false);
        
        //Seleciona o item que foi clicado na tabela.
        for (int i = 0; i < tipoCombo.getItemCount(); i++) {

            if (tipo.equals(((ItemTipo) tipoCombo.getItemAt(i)).getCodigo())) {
                tipoCombo.setSelectedIndex(i);
                break;
            }
            
            
        }
        
        updateTable();
        
    }*/
    
    private void edicaoOUcancelar() {
        cancelarButton.setText("Cancelar");
    }
    
        //private void updateTable() {
        //Lista os itens cadastrados no banco na tablela
        
    //}

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        cancelarButton = new javax.swing.JButton();
        okButton = new javax.swing.JButton();
        mensagemjLabel4 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        numeroTextField = new javax.swing.JTextField();
        qtdProdTextField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        tipoCombo = new javax.swing.JComboBox();
        jSeparator1 = new javax.swing.JSeparator();

        setTitle("Cadastro de Ordem de Produção");
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        cancelarButton.setText("Cancelar");
        cancelarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarButtonActionPerformed(evt);
            }
        });
        jPanel1.add(cancelarButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 90, 90, -1));

        okButton.setText("Incluir");
        okButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                okButtonMouseClicked(evt);
            }
        });
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });
        jPanel1.add(okButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 90, 90, -1));

        mensagemjLabel4.setForeground(new java.awt.Color(255, 0, 0));
        mensagemjLabel4.setText("..");
        jPanel1.add(mensagemjLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 100, -1, -1));

        jLabel1.setText("Codigo: ");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 20, -1, 20));

        jLabel4.setText("Qtd Prod:");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 60, -1, -1));

        numeroTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                numeroTextFieldActionPerformed(evt);
            }
        });
        numeroTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                numeroTextFieldKeyPressed(evt);
            }
        });
        jPanel1.add(numeroTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 20, 60, -1));

        qtdProdTextField.setName(""); // NOI18N
        qtdProdTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                qtdProdTextFieldActionPerformed(evt);
            }
        });
        qtdProdTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                qtdProdTextFieldKeyPressed(evt);
            }
        });
        jPanel1.add(qtdProdTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 60, 60, -1));

        jLabel3.setText("Produto: ");
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 20, -1, 20));

        tipoCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tipoComboActionPerformed(evt);
            }
        });
        jPanel1.add(tipoCombo, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 20, 370, 20));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 640, 140));
        getContentPane().add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 140, 610, 10));

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void cancelarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarButtonActionPerformed
      
    mensagemjLabel4.setText("");
    if (numeroTextField.getText().equals("")) {

        this.setVisible(true);

    } else {

        numeroTextField.setText("");
        numeroTextField.setEnabled(true);
        qtdProdTextField.setText("");
        cancelarButton.setText("Cancelar");
    }

}//GEN-LAST:event_cancelarButtonActionPerformed

private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
    OrdemProducaoBusinesDelegate delegate = new OrdemProducaoBusinesDelegate();
    
    if(numeroTextField.getText().equals("") || qtdProdTextField.getText().equals("")){
        mensagemjLabel4.setText("Cadastro inválido.");
    }else{
          delegate.create(Integer.parseInt(numeroTextField.getText()),
            ((ItemProduto)tipoCombo.getSelectedItem()).getCodigo(),
            Integer.parseInt(qtdProdTextField.getText()));
            this.setVisible(false);
    

    //Limpa os combos apos a insercao para permitir nova insercao
    numeroTextField.setText("");
    qtdProdTextField.setText("");
    cancelarButton.setText("Cancelar");  
    }
    

    


    
}//GEN-LAST:event_okButtonActionPerformed

private void okButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_okButtonMouseClicked

}//GEN-LAST:event_okButtonMouseClicked

private void numeroTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_numeroTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_numeroTextFieldActionPerformed

private void numeroTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_numeroTextFieldKeyPressed
cancelarButton.setText("Limpar");
mensagemjLabel4.setText("");
}//GEN-LAST:event_numeroTextFieldKeyPressed

private void qtdProdTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_qtdProdTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_qtdProdTextFieldActionPerformed

private void tipoComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tipoComboActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_tipoComboActionPerformed

private void qtdProdTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_qtdProdTextFieldKeyPressed
mensagemjLabel4.setText("");
}//GEN-LAST:event_qtdProdTextFieldKeyPressed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelarButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel mensagemjLabel4;
    private javax.swing.JTextField numeroTextField;
    private javax.swing.JButton okButton;
    private javax.swing.JTextField qtdProdTextField;
    private javax.swing.JComboBox tipoCombo;
    // End of variables declaration//GEN-END:variables

}
